const mysql = require('mysql2');

const connection = mysql.createConnection({
    host: '81.68.211.63',
    user: 'admin',
    password: 'admin',
    port: '3306',
    database: 'mine'
});

connection.connect((err) => {
    if (err) throw err;
    console.log('Connected to MySQL database!');
});

exports.connection = connection;

// exports.executeQuery = async (database = 'mine', query, callback) => {
//     const promisePool = pool(database).promise()
//     try {
//         // 使用async/await确保查询完毕再返回结果
//         const [rows, fields] = await promisePool.query(query);
//         console.log("config => rows:", rows)
//         // 记得关闭数据库连接
//         promisePool.end()
//         return callback(rows)
//     } catch (error) {
//         console.log(error);
//         // throw new Error(`查询失败：${error.message}`);
//     }
// }